package com.sunsys;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletLogin
 */
@WebServlet("/ServletLogin")
public class ServletLogin extends HttpServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.setContentType("text/html");
		PrintWriter writer = response.getWriter();
		
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		UserDAO user = new UserDAO();
		boolean result = user.login(username, password);
		
		System.out.println("Result:"+result);
		System.out.println("username:"+username);
		
		if(result == true) {
			RequestDispatcher dispatcher = request.getRequestDispatcher("/search.jsp");
			request.setAttribute("name", username);
			dispatcher.forward(request, response);
			
		}
		writer.println("Result:"+result);
		
		}
}
